% draw2L.m
% This Matlab script prints results for partial mesh cases after running topo2L.run AMPL script

partial;
fullmesh;

% use element wise devide, i.e., right divide in matlab
nmin = 1; nmax = 8; 
saving = (spare(nmin:nmax,2)+spare(nmin:nmax,3) - spare(nmin:nmax,4)) ./ spare(nmin:nmax,4)
saving2 = (spare2(nmin:nmax,2)+spare2(nmin:nmax,3) - spare2(nmin:nmax,4)) ./ spare2(nmin:nmax,4)

nmin = 1; nmax = 4; 
nsz = nmax-nmin+1;
figure;
%title ('Total Spare Capacity');
ylabel ('Total Spare Capacity');
xlabel ('Network');
hold on;
b1 = bar ( nmin:1:nmax, [spare(nmin:nmax,2)+spare(nmin:nmax,3), zeros(nsz,4)], 'groupable', 'c');
b2 = bar ( nmin:1:nmax, [spare(nmin:nmax,3), zeros(nsz,4)], 'groupable', 'b');
b3 = bar ( nmin:1:nmax, [zeros(nsz,1), spare(nmin:nmax,4),zeros(nsz,3)], 'groupable', 'g');

b12 = bar ( nmin:1:nmax, [zeros(nsz,3), spare2(nmin:nmax,2)+spare2(nmin:nmax,3), zeros(nsz,1)], 'groupable', 'y');
b22 = bar ( nmin:1:nmax, [zeros(nsz,3), spare2(nmin:nmax,3), zeros(nsz,1)], 'groupable', 'b');
b32 = bar ( nmin:1:nmax, [zeros(nsz,4), spare2(nmin:nmax,4)], 'groupable', 'm'); 

axis ([nmin-1 nmax+1 0 300]);
hold off;
legend ([b1(:,1), b2(:,1), b3(:,2), b12(:,4), b22(:,4), b32(:,5)], ...
   'Partial Mesh Top Layer Only [Model B]', 'Bottom Layer Only', 'Partial Mesh Common Pool', ...
   'Full Mesh Top Layer Only [Model B]', 'Bottom Layer Only', 'Full Mesh Common Pool', 2);

nmin = 5; nmax = 8; 
nsz = nmax-nmin+1;
figure;
%title ('Total Spare Capacity');
ylabel ('Total Spare Capacity');
xlabel ('Network');
axis ([nmin-1 nmax+1 0 3500]);
hold on;
b1b = bar ( nmin:1:nmax, [spare(nmin:nmax,2)+spare(nmin:nmax,3), zeros(nsz,4)], 'groupable', 'c');
b2b = bar ( nmin:1:nmax, [spare(nmin:nmax,3), zeros(nsz,4)], 'groupable', 'b');
b3b = bar ( nmin:1:nmax, [zeros(nsz,1), spare(nmin:nmax,4),zeros(nsz,3)], 'groupable', 'g');

b12b = bar ( nmin:1:nmax, [zeros(nsz,3), spare2(nmin:nmax,2)+spare2(nmin:nmax,3), zeros(nsz,1)], 'groupable', 'y');
b22b = bar ( nmin:1:nmax, [zeros(nsz,3), spare2(nmin:nmax,3), zeros(nsz,1)], 'groupable', 'b');
b32b = bar ( nmin:1:nmax, [zeros(nsz,4), spare2(nmin:nmax,4)], 'groupable', 'm'); 

hold off;
legend ([b1b(:,1), b2b(:,1), b3b(:,2), b12b(:,4), b22b(:,4), b32b(:,5)], ...
   'Partial Mesh Top Layer Only [Model B]', 'Bottom Layer Only', 'Partial Mesh Common Pool', ...
   'Full Mesh Top Layer Only [Model B]', 'Bottom Layer Only', 'Full Mesh Common Pool', 2);

nmin = 1; nmax = 8; 
nsz = nmax-nmin+1;
figure;
%title ('Redundancy Reduced in Common Pool Scheme');
ylabel ('Redundancy %');
xlabel ('Network');
axis ([nmin-0.5 nmax+0.5 0 100]);
hold on;
s1 = bar ([util(nmin:nmax,2),zeros(nsz,6)], 'groupable', 'c');
s2 = bar ([zeros(nsz,1), util(nmin:nmax,3),zeros(nsz,5)], 'groupable', 'b');
s3 = bar ([zeros(nsz,2),util(nmin:nmax,4),zeros(nsz,4)], 'groupable', 'g');

s12 = bar ([zeros(nsz,4), util2(nmin:nmax,2),zeros(nsz,2)], 'groupable', 'y');
s22 = bar ([zeros(nsz,5), util2(nmin:nmax,3),zeros(nsz,1)], 'groupable', 'b');
s32 = bar ([zeros(nsz,6),util2(nmin:nmax,4)], 'groupable', 'm');

hold off;
legend ([s1(:,1),s2(:,2),s3(:,3), s12(:,5),s22(:,6),s32(:,7)], ...
   'Partial Mesh Top Layer Only [Model B]', 'Bottom Layer Only', 'Partial Mesh Common Pool', ...
   'Full Mesh Top Layer Only [Model B]', 'Bottom Layer Only', 'Full Mesh Common Pool',0);


figure;
p4 = plot(saving*100, 'marker','+','markersize',12,...
   'markeredgecolor','b','markerfacecolor',[0 0 0],...
   'linestyle','-','color','b','linewidth',1);
hold on;
p5 = plot (saving2*100, 'marker','x','markersize',12,...
   'markeredgecolor','k','markerfacecolor',[0 0 0],...
   'linestyle','--','color','k','linewidth',1);
hold off;
ylabel ('Percentage Saving of the Total Spare Capacity using Common Pool');
xlabel ('Network');               
axis ([0.5 8.5 0 25]);
legend ([p4, p5], 'Partial Mesh', 'Full Mesh');

               

